#pragma once

#include "Socket.hpp"
#include "TcpServer.hpp"
#include <iostream>
#include <string>
#include <memory>
#include <unordered_map>

using namespace SocketModule;

const std::string gsapce = " ";
const std::string glinespace = "\r\n";

class HttpRequest
{
public:

    HttpRequest()
    {

    }

    std::string Serialize()
    {
        return std::string();
    }

    bool Deserialize(std::string& reqstr)
    {
        return true;
    }

    ~HttpRequest()
    {

    }

private:
    std::string _method;
    std::string _url;
    std::string _version;

    std::unordered_map<std::string, std::string> _headers;
    std::string _blankline;
    std::string _text;
};

class Http
{
public:

    Http(uint16_t port): tsvrp(std::make_unique<TcpServer>(port))
    {

    }

    void HandlerHttpRequest(std::shared_ptr<Socket>& sock, InetAddr& client)
    {
#ifndef DEBUG
#define DEBUG

        std::string httprequest;
        //浏览器发过来的是一个大的http字符串
        sock->Recv(&httprequest);
        std::cout << httprequest;

#endif
        //对请求字符串，进行反序列化
    }

    void Start()
    {
        tsvrp->Start([this](std::shared_ptr<Socket>& sock, InetAddr& client){
            this->HandlerHttpRequest(sock, client);
        }); 
    }

private:
    std::unique_ptr<TcpServer> tsvrp;
};

